/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package SnpDbHandling;

import SnpDbEntities.User;
import SnpDbEntities.UserPermissions;

/**
 *
 * @author Łukasz 'byku' Guzik
 */
public class AdminPermissionsPolicy extends UserPermissionsPolicy
{
    protected AdminPermissionsPolicy(User askingUser)
    {
	super(askingUser);
    }

    @Override
    public boolean canAddUser(User userToAdd)
    {
	if(userToAdd.getPermissions() != UserPermissions.ADMIN
		&& userToAdd.getPermissions() != UserPermissions.SUPER_ADMIN)
	    return true;
	else
	    return false;
    }

    @Override
    public boolean canDeleteUser(User userToDelete)
    {
	if(userToDelete.getPermissions() == UserPermissions.SUPER_ADMIN
		|| (askingUser.getId() != userToDelete.getId()
		&& userToDelete.getPermissions() == UserPermissions.ADMIN))
	{
	    return false;
	} else
	{
	    return true;
	}
    }

    @Override
    public boolean canDisEnableUser(User userToDisEnable)
    {
	if(userToDisEnable.getPermissions() == UserPermissions.SUPER_ADMIN)
	    return false;

	if(userToDisEnable.getPermissions() == UserPermissions.ADMIN
		&& askingUser.getId() != userToDisEnable.getId())
	    return false;

	return true;
    }

    @Override
    public boolean canUpdateUser(User userToUpdate, User newUserData)
    {
	if(userToUpdate.getPermissions() == UserPermissions.SUPER_ADMIN
		|| newUserData.getPermissions() == UserPermissions.SUPER_ADMIN)
	    return false;

	if(userToUpdate.getPermissions() == UserPermissions.ADMIN
		&& askingUser.getId() != userToUpdate.getId())
	    return false;

	if(userToUpdate.getPermissions() == UserPermissions.MODERATOR
		|| userToUpdate.getPermissions() == UserPermissions.NORMAL_USER)
	{
	    if(newUserData.getPermissions() == UserPermissions.SUPER_ADMIN
		    || newUserData.getPermissions() == UserPermissions.ADMIN)
		return false;
	}

	return true;
    }

    @Override
    public boolean canChangePublicCategories()
    {
	return true;
    }

    @Override
    public boolean canUpdatePublicSnippet()
    {
	return true;
    }
}
